<template>
	<scroll-view scroll-y height="100%" class="scrollBox" :style="{backgroundColor:bgColor}">
		<view class="sidebarBox">
			<view class="sidebarItem" :class="{on:item.value==nowIndex}" v-for="(item,index) in dataList" :key="index" @click="sidebarChange(item.value)">
				<view class="bar" :class="{on:item.value==nowIndex}"></view>
				<view class="text" :class="{on:item.value==nowIndex}">{{item.text||item}}</view>
				<view></view>
			</view>
		</view>
	</scroll-view>
</template>

<script>
	export default {
		name: "sidebar",
		props: {
			bgColor: {
				type: String,
				default: '#F7F7F7'
			}
		},
		data() {
			return {
				nowIndex: '',
				dataList: [{
					text: '餐饮美食'
				}, {
					text: '数码产品'
				}, {
					text: '休闲娱乐'
				}, {
					text: '五金紧固'
				}, {
					text: '工具耗材'
				}]
			};
		},
		methods: {
			setIndex(value) {
				this.nowIndex = value
			},
			sidebarChange(value) {
				this.nowIndex = value
				this.$emit('change', value)
			},
			initData(data) {
				console.log(data);
				this.dataList = data
				this.nowIndex = data[0].value
			},
		}
	}
</script>

<style lang="scss" scoped>
	.scrollBox {
		width: 100%;
		height: 100%;
		box-sizing: border-box;
		

		.sidebarBox {
			height: 100%;
		}
	}

	.sidebarItem {
		height: 100rpx;
		text-align: center;
		display: flex;
		align-items: center;
		justify-content: center;
		
		&.on{
			justify-content: space-between;
		}

		.text {
			color: #666666;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 30rpx;

			&.on {
				color: #6FA9FF;
			}
		}
		
		.bar{
			display: none;
			background-color: #038bff;
			width: 10rpx;
			height: 40rpx;
			border-radius: 16rpx;
			
			&.on{
				display: block;
			}
		}
	}
</style>